using System;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;

namespace Blog.Util
{
    public class SecurityHelper
    {
        public static string Encrypt(string pwd)
        {
             byte[] salt = new byte[128 / 8];
                //RandomNumberGenerator：加密随机数生成器创建加密型强随机值。
                using (var rng = RandomNumberGenerator.Create())
                {
                    rng.GetBytes(salt);
                }

                // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
               return Convert.ToBase64String(KeyDerivation.Pbkdf2(
                    password: pwd,
                    salt: salt,//计算种子
                    prf: KeyDerivationPrf.HMACSHA1,//加密方式
                    iterationCount: 10000,//迭代数
                    numBytesRequested: 256 / 8//期望得hash长度
                    ));

        }

    }
}